<template>
  <el-dialog
    title="选择题目"
    :close-on-click-modal="false"
    :visible.sync="visible"
    lock-scroll
    append-to-body
    width="80%"
    @close="close"
  >
    <el-row :gutter="20">
      <el-col :span="5">
        <el-input
          placeholder="题库名称"
          v-model="query1.questionbank"
          class="input-with-select"
        >
          <el-button slot="append" icon="el-icon-search"></el-button>
        </el-input>
        <JADP-table
          v-if="!randomFlag"
          v-loading="listLoading"
          :data="list"
          @sort-change="sortChange"
          style="margin-top: 10px;"
          @row-click="rowClick"
          height="550px"
        >
          <el-table-column prop="questionbank" label="题库名称" align="left" />
        </JADP-table>
        <el-table
          v-if="randomFlag"
          v-loading="listLoading"
          :data="list"
          @sort-change="sortChange"
          style="margin-top: 10px;"
          height="550px"
          border
        >
          <el-table-column label="单选" align="left" width="50">
            <template v-slot="{ row, $index }">
              <el-radio
                :label="$index"
                v-model="radio"
                class="tableRadio"
                @change.native="handleSelectionChangeTk(row)"
              >
              </el-radio>
            </template>
          </el-table-column>
          <el-table-column type="index" width="100" label="序号">
          </el-table-column>
          <el-table-column prop="questionbank" label="题库名称" align="left" />
        </el-table>
        <pagination
          :total="total"
          :page.sync="listQuery.currentPage"
          :limit.sync="listQuery.pageSize"
          layout="prev, pager, next"
          @pagination="init"
        />
      </el-col>
      <el-col :span="16" v-if="!randomFlag">
        <el-form @submit.native.prevent>
          <el-col :span="6">
            <el-form-item>
              <el-select
                v-model="query.topictype"
                placeholder="题目类型"
                clearable
              >
                <el-option
                  v-for="(item, index) in getDict('topictype')"
                  :key="index"
                  :label="item.dataName"
                  :value="item.id"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-select
                v-model="query.difficultion"
                placeholder="题目难度"
                clearable
              >
                <el-option
                  v-for="(item, index) in getDict('difficultion')"
                  :key="index"
                  :label="item.dataName"
                  :value="item.id"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-input v-model="query.stem" placeholder="题目名称" clearable>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="search()"
                >查询</el-button
              >
              <el-button icon="el-icon-refresh-right" @click="reset()"
                >重置</el-button
              >
            </el-form-item>
          </el-col>
        </el-form>
        <el-table
          v-loading="listLoading2"
          :data="list2"
          @sort-change="sortChange"
          height="550px"
          row-key="id"
          border
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="selection"
            align="center"
            :selectable="isChecked"
            reserve-selection
          />
          <el-table-column
            type="index"
            width="50"
            label="序号"
            align="center"
          />
          <el-table-column prop="stem" label="题干" align="left" width="650px">
            <template v-slot="{ row }">
              <div>
                <span
                  class="zhankai"
                  @click="$set(row, 'openFlag', !row.openFlag)"
                  >{{ row.openFlag ? "收起" : "展开" }}</span
                >
                <div class="subject_body">
                  <div v-html="row.stem" class="stem"></div>
                  <!--单选题  -->
                  <div
                    v-show="row.openFlag"
                    v-if="row.topictype === '7280c24ba6bf410997c739637706e7e6'"
                  >
                    <el-radio-group disabled v-model="row.result">
                      <ul>
                        <li v-for="(val, inx) in row.optionsum" :key="inx">
                          <el-radio :label="val.id">{{ val.value }}</el-radio>
                        </li>
                      </ul>
                    </el-radio-group>
                    <div>
                      <el-row>
                        <el-col :span="3">解析：</el-col>
                        <el-col :span="22">
                          <div v-html="row.answeranalysis"></div>
                        </el-col>
                      </el-row>
                    </div>
                  </div>
                  <!--多选题  -->
                  <div
                    v-show="row.openFlag"
                    v-if="row.topictype === '1d3f7e7e22c94e49ba95f52e3ec9e3af'"
                  >
                    <el-checkbox-group disabled v-model="row.result">
                      <ul>
                        <li v-for="(val, inx) in row.optionsum" :key="inx">
                          <!-- <el-radio :label="val.id">{{ val.value }}</el-radio> -->
                          <el-checkbox :label="val.id">{{
                            val.value
                          }}</el-checkbox>
                        </li>
                      </ul>
                    </el-checkbox-group>
                    <div>
                      <el-row>
                        <el-col :span="3">解析：</el-col>
                        <el-col :span="22">
                          <div v-html="row.answeranalysis"></div>
                        </el-col>
                      </el-row>
                    </div>
                  </div>
                  <!--填空题  -->
                  <div
                    v-show="row.openFlag"
                    v-if="row.topictype === 'f0b4073bc9ad4426b87cbc70d4526cf6'"
                  >
                    <div style="margin:20px 0">
                      答案：
                      <span
                        v-for="(val, inx) in row.optionsum"
                        :key="inx"
                        style="margin-right:10px"
                      >
                        <!-- <el-radio :label="val.id">{{ val.value }}</el-radio> -->
                        {{ val.value }};
                      </span>
                    </div>
                    <div>
                      <el-row>
                        <el-col :span="3">解析：</el-col>
                        <el-col :span="22">
                          <div v-html="row.answeranalysis"></div>
                        </el-col>
                      </el-row>
                    </div>
                  </div>
                  <!--判断题  -->
                  <div
                    v-show="row.openFlag"
                    v-if="row.topictype === 'ee505074164e4d0bb54e4a5136b123fb'"
                  >
                    <div style="margin:20px 0">
                      答案：
                      <el-radio-group disabled v-model="row.result">
                        <el-radio label="正确"></el-radio>
                        <el-radio label="错误"></el-radio>
                      </el-radio-group>
                    </div>
                    <div>
                      <el-row>
                        <el-col :span="3">解析：</el-col>
                        <el-col :span="22">
                          <div v-html="row.answeranalysis"></div>
                        </el-col>
                      </el-row>
                    </div>
                  </div>
                  <!-- 简单题 -->
                  <div
                    v-show="row.openFlag"
                    v-if="row.topictype === '07ba1e3b779b4e1db3c1318d0f80a688'"
                  >
                    <div style="margin:20px 0">
                      答案：
                      <p v-html="row.result"></p>
                    </div>
                    <div>
                      <el-row>
                        <el-col :span="3">解析：</el-col>
                        <el-col :span="22">
                          <div v-html="row.answeranalysis"></div>
                        </el-col>
                      </el-row>
                    </div>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="topictype" label="题目类型" align="left">
            <template v-slot="{ row }">
              {{ getDict("topictype", row.topictype) }}
            </template>
          </el-table-column>
          <el-table-column prop="difficultion" label="难度" align="left">
            <template v-slot="{ row }">
              {{ getDict("difficultion", row.difficultion) }}
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :total="total3"
          :page.sync="listQuery3.currentPage"
          :limit.sync="listQuery3.pageSize"
          @pagination="initData"
        />
      </el-col>

      <el-col :span="3" v-if="!randomFlag">
        <h3 class="right-title">试卷题型统计</h3>
        <ul style="margin-top:50px">
          <li class="topictype">
            单选题：{{
              getnum("7280c24ba6bf410997c739637706e7e6") * 1 + this.danxuan
            }}
          </li>
          <li class="topictype">
            多选题：{{
              getnum("1d3f7e7e22c94e49ba95f52e3ec9e3af") * 1 + this.duoxuan
            }}
          </li>
          <li class="topictype">
            判断题：{{
              getnum("ee505074164e4d0bb54e4a5136b123fb") * 1 + this.panduan
            }}
          </li>
          <li class="topictype">
            填空题：{{
              getnum("f0b4073bc9ad4426b87cbc70d4526cf6") * 1 + this.tiankong
            }}
          </li>
          <li class="topictype">
            简答题：{{
              getnum("07ba1e3b779b4e1db3c1318d0f80a688") * 1 + this.jianda
            }}
          </li>
        </ul>
      </el-col>
      <!-- <el-col
        style="min-height:630px;border-right:1px solid #ccc;"
        :span="9"
        v-if="randomFlag"
      >
        <el-form
          ref="elForm"
          :model="dataForm"
          size="small"
          label-width="100px"
          label-position="right"
        >
          <el-col :span="24">
            <el-form-item label="选择类型：" prop="radio">
              <el-radio-group v-model="dataForm.radio" @change="typeChange">
                <el-radio label="题型"></el-radio>
                <el-radio label="难度"></el-radio>
                <el-radio label="知识点"></el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="dataForm.radio === '题型'">
            <el-form-item label="选择题型：" prop="topictype">
              <el-checkbox-group
                v-model="dataForm.topictype"
                @change="checkboxChange"
              >
                <el-checkbox
                  :label="item.id"
                  v-for="item in getDict('topictype')"
                  :key="item.id"
                >
                  {{ item.dataName }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="dataForm.radio === '难度'">
            <el-form-item label="选择难度：" prop="difficultion">
              <el-radio-group
                v-model="dataForm.difficultion"
                @change="radioChange"
              >
                <el-radio
                  :label="item.id"
                  v-for="item in getDict('difficultion')"
                  :key="item.id"
                  >{{ item.dataName }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-form>
        <div v-if="dataForm.radio === '知识点'">
          <JADP-table
            v-loading="listLoading"
            :data="zsdList"
            @sort-change="sortChange"
            :has-c="!!query.tkid"
            height="550px"
            ref="knowledgePoints"
            @selection-change="handleSelectionChange2"
          >
            <el-table-column prop="name" label="知识点名称" align="left" />
            <el-table-column label="知识点分类" prop="assortment" algin="left">
            </el-table-column>
          </JADP-table>
          <pagination
            :total="total2"
            :page.sync="listQuery2.currentPage"
            :limit.sync="listQuery2.pageSize"
            layout="prev, pager, next"
            @pagination="initData2"
          />
        </div>
      </el-col> -->
      <el-col
        :span="9"
        style="min-height:630px;border-right:1px solid #ccc;"
        v-if="randomFlag"
      >
        <h3 style="margin-bottom:10px">抽取条件:</h3>
        <el-form
          ref="elForm"
          :rules="rules"
          :model="dataForm"
          size="small"
          label-width="100px"
          label-position="right"
        >
          <el-col :span="24">
            <el-form-item label="选择题型：" prop="topictype">
              <el-select v-model="dataForm.topictype" placeholder="请选择">
                <el-option
                  v-for="item in getDict('topictype')"
                  :key="item.id"
                  :label="item.dataName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="选择难度：" prop="difficultion">
              <el-checkbox-group
                v-model="checkList"
                @change="handleCheckedCitiesChange"
              >
                <el-checkbox
                  v-for="item in getDict('difficultion')"
                  :key="item.id"
                  :label="item.id"
                >
                  {{ item.dataName }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-form>
        <div>
          <JADP-table
            v-loading="listLoading"
            :data="zsdList"
            @sort-change="sortChange"
            has-c
            ref="knowledgePoints"
            @selection-change="handleSelectionChange2"
          >
            <el-table-column prop="name" label="知识点名称" align="left" />
            <!-- <el-table-column label="知识点分类" prop="assortment" algin="left">
            </el-table-column> -->
          </JADP-table>
          <pagination
            :total="total2"
            :page.sync="listQuery2.currentPage"
            :limit.sync="listQuery2.pageSize"
            layout="prev, pager, next"
            @pagination="initData2"
          />
          <div style="text-align: center; margin-top:10px">
            <el-button type="primary" @click="addConditions"
              >确定选取</el-button
            >
          </div>
        </div>
      </el-col>
      <el-col :span="10" v-if="randomFlag">
        <el-row>
          <el-col :span="12">
            <h3 style="margin-bottom:10px">选取设置:</h3></el-col
          >
          <el-col :span="12" style="text-align: right">
            <div class="summary">
              共选择<span class="total_score">{{ total_score }}</span
              >道题目
            </div></el-col
          >
        </el-row>

        <div
          class="rule-node-cascade"
          v-for="(item, index) in typeList"
          :key="index"
        >
          <el-row style="line-height: 28px;">
            <el-col :span="5">
              <span>题型:{{ getDict("topictype", item.topictype) }}</span>
            </el-col>
            <el-col :span="5">
              <span>难度：{{ item.difficultionName }}</span>
            </el-col>
            <el-col :span="5">
              <span>知识点：{{ item.knowledgePointsName }}</span>
            </el-col>
            <el-col :span="6">
              <div class="handler_bar">
                选取
                <el-input-number
                  v-model="item.subjectNum"
                  controls-position="right"
                  size="mini"
                  :min="0"
                  :max="item.list.length"
                  :step="1"
                ></el-input-number>
                /{{ item.list.length }}题
              </div>
            </el-col>
            <el-col :span="2" :offset="1"
              ><div class="del" @click="typeListRemove(item, index)">
                移除
              </div></el-col
            >
          </el-row>
        </div>
      </el-col>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="dataFormSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import request from "@/utils/request";
import _ from "lodash";
export default {
  name: "selectedTopic",
  props: {
    TmList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    var checkAge = (rule, value, callback) => {
      if (!this.checkList.length) {
        return callback(new Error("请至少选择一个难度"));
      }
      callback();
    };
    return {
      visible: false,
      query1: {
        questionbank: undefined
      },
      query: {
        topictype: undefined,
        difficultion: undefined,
        stem: undefined,
        tkid: undefined
      },
      list: [],
      list2: [],
      checkList: [],
      multipleSelection: [],
      multipleSelection2: [],
      listLoading: false,
      listLoading2: false,
      total: 0,
      total2: 0,
      total3: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime"
      },
      listQuery3: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime"
      },
      listQuery2: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime"
      },
      paperid: "", // 试卷id
      courseid: "", // 课程id
      subjectEntityList: [], //已选题目数组
      danxuan: 0,
      duoxuan: 0,
      panduan: 0,
      tiankong: 0,
      jianda: 0,
      randomFlag: false,
      dataForm: {
        topictype: "",
        difficultionName: "",
        difficultionId: "",
        knowledgePointsName: "",
        knowledgePointsId: ""
      },
      form: {
        subjectNum: 1
      },
      zsdList: [],
      radio: "",
      typeObj: {},
      typeList: [],
      tkList: [],
      rules: {
        topictype: [
          {
            required: true,
            message: "请选择一个题型",
            trigger: "change"
          }
        ],
        difficultion: [
          {
            validator: checkAge
          }
        ]
      }
    };
  },
  watch: {
    multipleSelection2(val) {
      this.danxuan = 0;
      this.duoxuan = 0;
      this.panduan = 0;
      this.tiankong = 0;
      this.jianda = 0;
      val.forEach(item => {
        if (item.topictype === "7280c24ba6bf410997c739637706e7e6") {
          this.danxuan++;
        } else if (item.topictype === "1d3f7e7e22c94e49ba95f52e3ec9e3af") {
          this.duoxuan++;
        } else if (item.topictype === "ee505074164e4d0bb54e4a5136b123fb") {
          this.panduan++;
        } else if (item.topictype === "f0b4073bc9ad4426b87cbc70d4526cf6") {
          this.tiankong++;
        } else {
          this.jianda++;
        }
      });
    }
  },
  computed: {
    getnum() {
      return function(id) {
        let num = 0;
        this.TmList.forEach(item => {
          if (item.topictype === id) {
            num++;
          }
        });
        return num;
      };
    },
    total_score() {
      let total_score = 0;
      this.typeList.forEach(item => (total_score += item.subjectNum));
      return total_score;
    }
  },
  methods: {
    //添加随机试卷抽取条件
    addConditions() {
      if (!this.query.tkid) {
        return this.$message.warning("请选择题库");
      }
      this.$refs.elForm.validate(valid => {
        if (valid) {
          //深克隆，防止query_和this.dataForm指向同一内存地址
          let query_ = JSON.parse(JSON.stringify(this.dataForm));
          request({
            url: "/api/subject/Xy_ks_subject/getSelectList",
            method: "post",
            data: {
              topictype: query_.topictype,
              difficultion: query_.difficultionId,
              zsdid: query_.knowledgePointsId,
              tkid: this.query.tkid
            }
          }).then(res => {
            query_.list = res.data;
            query_.subjectNum = 0;
            this.typeList.push(query_);
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    //难度多选
    handleCheckedCitiesChange(val) {
      let newArr = [];
      val.forEach(item => {
        newArr.push(
          this.getDict("difficultion").filter(value => value.id === item)[0]
        );
      });
      this.dataForm.difficultionName = newArr.map(item => item.dataName).join();
      this.dataForm.difficultionId = newArr.map(item => item.id).join();
    },

    //移除
    typeListRemove(value, index) {
      this.typeList.splice(index, 1);
    },

    init() {
      this.visible = true;
      this.listLoading = true;
      let _query = {
        ...this.listQuery,
        ...this.query1,
        organizeId:this.$store.getters.organizeId
      };
      let query = {};
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join();
        } else {
          query[key] = _query[key];
        }
      }
      request({
        url: `/api/questionbank/Xy_ks_questionbank`,
        method: "get",
        data: query
      }).then(res => {
        this.list = res.data.list;
        this.total = res.data.pagination.total;
        this.listLoading = false;
      });
    },

    rowClick(row) {
      this.query.tkid = row.id;
      this.initData();
    },
    sortChange({ column, prop, order }) {
      this.listQuery.sort = order == "ascending" ? "asc" : "desc";
      this.listQuery.sidx = !order ? "" : prop;
      this.init();
    },
    initData() {
      this.listLoading2 = true;
      let _query = {
        ...this.listQuery3,
        ...this.query,
        organizeId:this.$store.getters.organizeId
      };
      let query = {};
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join();
        } else {
          query[key] = _query[key];
        }
      }
      request({
        url: `/api/subject/Xy_ks_subject`,
        method: "get",
        data: query
      }).then(res => {
        this.list2 = res.data.list;
        this.list2.forEach(item => {
          item.openFlag = false;
          // 判断不等于简答题，不等于判断题
          if (
            item.topictype !== "07ba1e3b779b4e1db3c1318d0f80a688" &&
            item.topictype !== "ee505074164e4d0bb54e4a5136b123fb"
          ) {
            item.result = JSON.parse(item.result);
            item.optionsum = JSON.parse(item.optionsum);
          }
        });
        this.list2 = JSON.parse(JSON.stringify(this.list2));
        this.total3 = res.data.pagination.total;
        this.listLoading2 = false;
      });
    },
    // 获取题库所有数据
    getTkList() {
      request({
        url: `/api/subject/Xy_ks_subject/getAll/${this.query.tkid}`,
        method: "get"
      }).then(res => {
        console.log(res, 5555);
        this.tkList = res.data;
        this.tkList.forEach(item => {
          item.openFlag = false;
          // 判断不等于简答题，不等于判断题
          if (
            item.topictype !== "07ba1e3b779b4e1db3c1318d0f80a688" &&
            item.topictype !== "ee505074164e4d0bb54e4a5136b123fb"
          ) {
            item.result = JSON.parse(item.result);
            item.optionsum = JSON.parse(item.optionsum);
          }
        });
        this.tkList = JSON.parse(JSON.stringify(this.tkList));
      });
    },
    initData2() {
      this.listLoading = true;
      let _query = {
        ...this.listQuery,
        // ...this.query,
        organizeId:this.$store.getters.organizeId
      };
      let query = {};
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join();
        } else {
          query[key] = _query[key];
        }
      }
      request({
        url: `/api/knowledgepoint/Xy_ks_knowledgepoint`,
        method: "get",
        data: query
      }).then(res => {
        this.zsdList = res.data.list;
        this.total2 = res.data.pagination.total;
        this.listLoading = false;
      });
    },
    handleSelectionChange(val) {
      const res = val.map(item => item.id);
      this.multipleSelection = res;
      this.multipleSelection2 = val;
    },

    //确定
    dataFormSubmit() {
      // console.log("添加题库", this.paperid, this.multipleSelection.join());
      // 判断是否选中题库

      // return;

      // 判断有无试卷id来确定是否试卷和练习
      if (this.paperid) {
        // 判断手动添加还是随机添加
        if (this.randomFlag) {
          let newArr = [];
          this.typeList.forEach(item => {
            newArr.push(...this.getArrayItems(item.list, item.subjectNum));
          });
          console.log(newArr, "newArr");
          if (!newArr.length) return this.$message.warning("请至少选择一题");
          let newArrId = newArr.map(item => item.id);
          request({
            url: `/api/manualselect/Xy_ks_subject_paper`,
            method: "POST",
            data: {
              paperid: this.paperid,
              tkid: this.query.tkid,
              subid: newArrId.join()
            }
          }).then(res => {
            this.$message.success("操作成功");
            this.visible = false;
            this.$emit("refresh", true);
          });
        } else {
          request({
            url: `/api/manualselect/Xy_ks_subject_paper`,
            method: "POST",
            data: {
              paperid: this.paperid,
              tkid: this.query.tkid,
              subid: this.multipleSelection.join()
            }
          }).then(res => {
            this.$message.success("操作成功");
            this.visible = false;
            this.multipleSelection = [];
            this.$emit("refresh", true);
          });
        }
      } else {
        if (!this.multipleSelection.join())
          return this.$message.warning("请至少选择一题");
        request({
          url: `/api/manualselect/Xy_ks_subject_paper`,
          method: "POST",
          data: {
            courseid: this.courseid,
            tkid: this.query.tkid,
            subid: this.multipleSelection.join()
          }
        }).then(res => {
          this.$message.success("操作成功");
          this.visible = false;
          this.multipleSelection = [];
          this.$emit("refresh", true);
        });
      }
    },
    // 判断题目是否可选，重复不可选
    isChecked(row) {
      if (this.subjectEntityList.includes(row.id)) {
        return false;
      } else {
        return true;
      }
    },

    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime"
      };
      this.initData();
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined;
      }
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime"
      };
      this.initData();
    },
    close() {
      this.list2 = [];
      this.$emit("refresh", true);
    },
    //选择题型
    checkboxChange(value) {
      if (!this.query.tkid) {
        this.dataForm.topictype = [];
        return this.$message.warning("请先选择题库");
      }
      // request({
      //   url: `/api/subject/Xy_ks_subject/randomSelection`,
      //   method: "get",
      //   data: {
      //     tkid: this.Tklist,
      //     topictype: value.join()
      //   }
      // }).then(res => {
      //   console.log(res, 22);
      //   // this.typeObj = res.data;
      //   // value.forEach(item => (this.form[item] = 1));
      // });
      // let Obj = {
      //   id: null,
      //   subjectNum: 1,
      //   list: []
      // };
      // let newArr = this.list2.filter(item => value.includes(item.topictype));
      this.typeList = [];
      // 去重
      let subList = _.pullAllBy(this.tkList, this.subjectEntityList, "id");
      value.forEach((item, index) => {
        this.typeList[index] = {};
        this.typeList[index].id = item;
        this.typeList[index].subjectNum = "";
        this.typeList[index].list = subList.filter(
          val => val.topictype === item
        );
      });
      this.typeList = JSON.parse(JSON.stringify(this.typeList));
    },
    // 选择难度
    radioChange(value) {
      if (!this.query.tkid) {
        this.dataForm.difficultion = "";
        return this.$message.warning("请先选择题库");
      }

      // request({
      //   url: `/api/subject/Xy_ks_subject/randomSelection`,
      //   method: "get",
      //   data: {
      //     difficultion: value
      //   }
      // }).then(res => {
      //   this.typeObj = res.data;
      //   console.log(res.data, 333);
      // });

      let subList = _.pullAllBy(this.tkList, this.subjectEntityList, "id");
      this.typeList = [];
      this.typeList[0] = {};
      this.typeList[0].id = value;
      this.typeList[0].subjectNum = "";
      this.typeList[0].list = subList.filter(val => val.difficultion === value);
      this.typeList = JSON.parse(JSON.stringify(this.typeList));
    },
    //选择知识点
    handleSelectionChange2(val) {
      // if (!this.query.tkid) {
      //   return this.$message.warning("请先选择题库");
      // }
      const res = val.map(item => item.id).join();
      const knowledgePointsName = val.map(item => item.name).join();
      this.dataForm.knowledgePointsId = res;
      this.dataForm.knowledgePointsName = knowledgePointsName;
      // request({
      //   url: `/api/subject/Xy_ks_subject/randomSelection`,
      //   method: "get",
      //   data: {
      //     zsdid: this.dataForm.knowledgePoints.join()
      //   }
      // }).then(res => {
      //   this.typeObj = res.data;
      //   console.log(res, 444);
      // });
      // let subList = _.pullAllBy(this.tkList, this.subjectEntityList, "id");
      // this.typeList = [];
      // this.dataForm.knowledgePoints.forEach((item, index) => {
      //   this.typeList[index] = {};
      //   this.typeList[index].id = item;
      //   this.typeList[index].subjectNum = "";
      //   this.typeList[index].list = subList.filter(val => val.zsdid === item);
      // });
      // this.typeList = JSON.parse(JSON.stringify(this.typeList));
    },
    // 选择题库
    handleSelectionChangeTk(val) {
      // this.Tklist = val.id;
      // this.typeChange();
      this.query.tkid = val.id;
      console.log(this.query.tkid, 444);
      this.initData();
      this.getTkList();
    },

    // 类型选择
    typeChange() {
      // if (!this.multipleSelection.length) {
      //   this.dataForm.radio = "题型";
      //   return this.$message.warning("请先选择题库");
      // }
      // 切换置空
      this.typeList = [];
      this.dataForm.topictype = [];
      this.dataForm.knowledgePoints = [];
      this.dataForm.difficultion = "";
      this.form.subjectNum = "";
    },

    //随机抽取
    getArrayItems(arr, num) {
      //新建一个数组,将传入的数组复制过来,用于运算,而不要直接操作传入的数组;
      var temp_array = new Array();
      for (var index in arr) {
        temp_array.push(arr[index]);
      }
      //取出的数值项,保存在此数组
      var return_array = new Array();
      for (var i = 0; i < num; i++) {
        //判断如果数组还有可以取出的元素,以防下标越界
        if (temp_array.length > 0) {
          //在数组中产生一个随机索引
          var arrIndex = Math.floor(Math.random() * temp_array.length);
          //将此随机索引的对应的数组元素值复制出来
          return_array[i] = temp_array[arrIndex];
          //然后删掉此索引的数组元素,这时候temp_array变为新的数组
          temp_array.splice(arrIndex, 1);
        } else {
          //数组中数据项取完后,退出循环,比如数组本来只有10项,但要求取出20项.
          break;
        }
      }
      return return_array;
    }
  }
};
</script>
<style scoped lang="scss">
>>> .el-dialog {
  margin-top: 10vh !important;
}
>>> .el-dialog__header {
  border-bottom: 1px solid #cccccc;
}
>>> .el-dialog__body {
  padding: 10px;
}
.subject_body {
  line-height: 22px;
  ul {
    margin-top: 20px;
    li {
      line-height: 30px;
      >>> .el-radio__label {
        font-size: 16px;
      }
    }
  }
  .stem {
    display: inline-block;
    margin-top: 15px;
  }
}

.zhankai {
  cursor: pointer;
  float: right;
  color: #409eff;
}
.right-title {
  text-align: center;
}
.topictype {
  margin-top: 20px;
  font-size: 16px;
  list-style: none;
}

.summary {
  padding-left: 20px;
  margin-bottom: 10px;
  .total_score {
    padding: 0 4px;
    font-size: 18px;
    color: #ff6700;
    vertical-align: middle;
  }
}
.rule-node-cascade {
  margin-bottom: 10px;
  padding: 10px;
  border: 1px dashed #409eff;
  .displayed_rule {
    padding-top: 5px;
    display: inline-block;
    min-height: 26px;
    .label {
      padding-right: 5px;
      font-weight: 700;
    }
  }
  .handler_bar {
    float: right;
    width: max-content;
    padding-left: 15px;
    text-align: right;
    >>> .el-input-number {
      width: 80px;
    }
    >>> .el-input__inner {
      padding: 5px;
      width: 80px;
    }
  }
  .del {
    color: #409eff;
    cursor: pointer;
  }
}
.tableRadio {
  >>> .el-radio__label {
    display: none;
  }
}
</style>
